package com.service.impl;

import com.domain.Article;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.ArticleMapper;
import com.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ArticleService")
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public PageInfo<Article> selectAll(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Article> articleList = articleMapper.selectAll();
        PageInfo<Article> pageInfo = new PageInfo<Article>(articleList);
        return pageInfo;
    }

    @Override
    public void delete(int id) {
        articleMapper.delete(id);
    }

    @Override
    public void insert(Article article) {
        articleMapper.insert(article);
    }

    @Override
    public void update(Article article) {
        articleMapper.update(article);
    }

    @Override
    public Article selectById(int id) {
        return articleMapper.selectById(id);
    }

    public PageInfo<Article> queryByOne(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Article> articleList = articleMapper.queryByOne();
        PageInfo<Article> pageInfo = new PageInfo<Article>(articleList);
        return pageInfo;
    }

    public PageInfo<Article> queryByZero(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Article> articleList = articleMapper.queryByZero();
        PageInfo<Article> pageInfo = new PageInfo<Article>(articleList);
        return pageInfo;
    }

}
